package com.hc.demo.controller;

import com.hc.demo.domain.Users;
import com.hc.demo.dto.ResultResponse;
import com.hc.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController  //因为我们是前后端分离的项目  前端--json格式数据交互--后端
public class UsersController {

    @Autowired
    UserService userService;
    /**
     * 登录接口
     */
    @RequestMapping("/login")
    public ResultResponse login(@RequestBody Users users){
        System.out.println("users:"+users.getUserId()+","+users.getPassword());
        //return new ResultResponse(200,"登录成功");
        return userService.login(users);
    }
    /**
     * 注册接口
     */
    @PostMapping("register")
    public ResultResponse register(@RequestBody Users users){
        return userService.regiter(users);
    }
    /**
     * 校验手机号码是否已经注册的接口
     */
    @RequestMapping("/validatePhone")
    public ResultResponse validatePhone(@RequestBody Users users){
        return userService.validatePhone(users.getUserId());
    }
}